package com.ficus.road.maintain.core.model.smartnew;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 智慧决策计算结果
 *
 * @author xiawen yang
 * @date 2022/7/20 下午3:37
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SmartDecisionResponse {
    @Id
    private String id;
    /**
     * 智能发现结果
     */
    private SmartDiscoveryResponse smartDiscoveryResponse;
    /**
     * 智能检测结果
     */
    private SmartInspectionResponse smartInspectionResponse;
    /**
     * 智能排序结果
     */
    private SmartSortingResponse smartSortingResponse;
    /**
     * 智能估价结果
     */
    private SmartValuationResponse smartValuationResponse;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    public static SmartDecisionResponse ofAllResponse() {
        return SmartDecisionResponse.builder()
                .smartDiscoveryResponse(new SmartDiscoveryResponse())
                .smartInspectionResponse(new SmartInspectionResponse())
                .smartSortingResponse(new SmartSortingResponse())
                .smartValuationResponse(new SmartValuationResponse())
                .createTime(LocalDateTime.now())
                .build();
    }

    public static SmartDecisionStatistic convert2SmartDecisionStatistic(SmartDecisionResponse response) {
        int fake = response.getSmartInspectionResponse().getMaintainIds().size() + response.getSmartInspectionResponse().getProjectIds().size();
        // todo: 先让项目初筛==智能巡查, end==0
        return SmartDecisionStatistic.builder()
                .inspection(fake)
                .screening(fake)
                .end(0)
                .maintain(response.getSmartInspectionResponse().getMaintainIds().size())
                .project(response.getSmartInspectionResponse().getProjectIds().size())
                .type1(response.getSmartSortingResponse().getType1())
                .type2(response.getSmartSortingResponse().getType2())
                .type3(response.getSmartSortingResponse().getType3())
                .type4(response.getSmartSortingResponse().getType4())
                .type5(response.getSmartSortingResponse().getType5())
                .reserve(response.getSmartSortingResponse().getType6())
                .roadMoney(response.getSmartValuationResponse().getMoneyAfterMerge())
                .sectionMoney(response.getSmartValuationResponse().getMoneyBeforeMerge())
                .build();
    }
    public static SmartDecisionStatistic convert2SmartDecisionStatistic1(SmartDecisionResponse response) {
        int fake = response.getSmartInspectionResponse().getMaintainIds().size() + response.getSmartInspectionResponse().getProjectIds().size();
        // todo: 先让项目初筛==智能巡查, end==0
        return SmartDecisionStatistic.builder()
                .inspection(fake)
                .screening(fake)
                .end(0)
                .maintain(response.getSmartInspectionResponse().getMaintainIds().size())
                .project(response.getSmartInspectionResponse().getProjectIds().size())
                .type1(response.getSmartSortingResponse().getType1())
                .type2(response.getSmartSortingResponse().getType2())
                .type3(response.getSmartSortingResponse().getType3())
                .type4(response.getSmartSortingResponse().getType4())
                .type5(response.getSmartSortingResponse().getType5())
                .reserve(response.getSmartSortingResponse().getType6())
                .roadMoney(response.getSmartValuationResponse().getMoneyAfterMerge())
                .sectionMoney(response.getSmartValuationResponse().getMoneyBeforeMerge())
                .build();
    }

    @Data
    public static class SmartDiscoveryResponse {
        /**
         * 智能巡查数量
         */
        private long smartDetectCount;
        /**
         * 项目初筛id列表
         */
        private List<String> screeningIds;
        /**
         * 结束id列表
         */
        private List<String> finishIds;
    }

    @Data
    public static class SmartInspectionResponse {
        /**
         * 日常养护id列表
         */
        private List<String> maintainIds;
        /**
         * 工程项目id列表
         */
        private List<String> projectIds;
    }

    @Data
    public static class SmartSortingResponse {
        /**
         * 合并前的排分表
         */
        private List<SmartTable> tablesBeforeMerge;
        /**
         * 合并后的排分表
         */
        private List<SmartTable> tablesAfterMerge;
        /**
         * 合并前的储备库
         */
        private List<SmartTable> reservesBeforeMerged;
        /**
         * 合并后的储备库
         */
        private List<SmartTable> reservesAfterMerged;
        /**
         * 第一大类
         */
        private int type1;
        /**
         * 第二大类
         */
        private int type2;
        /**
         * 第三大类
         */
        private int type3;
        /**
         * 第四大类
         */
        private int type4;
        /**
         * 第五大类
         */
        private int type5;
        /**
         * 第六大类(合并前的储备库数量)
         */
        private int type6;
    }

    @Data
    public static class SmartValuationResponse {
        private double moneyBeforeMerge;

        private double moneyAfterMerge;
    }
}
